# module geometry.xyz

import math
import geometry.xy

class XYZ:
	#########################################################################################
	# A 3-D point with common mathematical operations
	#########################################################################################
	def __init__(self,x,y,z):
		self.x = float(x)
		self.y = float(y)
		self.z = float(z)
	def __repr__(self):
		return 'XYZ' + str((self.x,self.y,self.z))
	def __add__(self,pt):
		"""Adds another point (or vector) to this point"""
		return XYZ(self.x+pt.x,self.y+pt.y,self.z+pt.z)
	def __sub__(self,pt):
		"""Subtracts another point from this point"""
		return XYZ(self.x-pt.x,self.y-pt.y,self.z-pt.z)
	def __mul__(self,a):
		"""Multiplies the object by a scalar"""
		f = float(a)
		return XYZ(f*self.x,f*self.y,f*self.z)
	def __rmul__(self,a):
		"""Multiplies the object by a scalar"""
		f = float(a)
		return XYZ(f*self.x,f*self.y,f*self.z)
	def __div__(self,a):
		"""Divides the object by a scalar"""
		f = float(a)
		return XYZ(self.x/f,self.y/f,self.z/f)
	def __abs__(self):
		"""Returns the magnitude of the object"""
		return math.sqrt(self.x*self.x + self.y*self.y+self.z*self.z)
	def __complex__(self):
		"""Returns the complex representation of the object"""
		return complex(self.x,self.y)
	def tuple(self):
		"""Returns the object as a tuple"""
		return (self.x,self.y,self.z)
	def distance2(self,pt):
		"""Returns the distance squared

		Returns the distance between self and pt as a float"""
		assert isinstance(pt,XYZ)
		return (pt.x-self.x)**2 + (pt.y-self.y)**2 + (pt.z-self.z)**2
	def magnitude(self):
		"""Returns the magnitude (length) of the object"""
		return math.sqrt(self.x**2 + self.y**2+self.z**2)
	def unitNormal(self):
		"""Returned as an XYZ"""
                raise "Not implemented"
        def XY(self):
                return geometry.xy.XY(self.x,self.y)
